<!-- 申请开票 -->
<template>
  <el-drawer
    v-model="drawerVisible"
    :close-on-click-modal="false"
    :destroy-on-close="true"
    size="1000px"
    :title="drawerProps.title"
  >
    <el-form
      ref="ruleFormRef"
      label-position="top"
      require-asterisk-position="right"
      :inline="true"
      :rules="rules"
      :model="params"
    >
      <div class="p-title w-100 mb-12">合同信息</div>
      <div class="form-inline-wrap">
        <el-form-item label="收款账户" prop="collectionAccount">
          <el-select v-model="params.collectionAccount" placeholder="请选择收款账户" clearable>
            <el-option v-for="item in businessType" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="选择合同">
          <el-select v-model="params.contract" placeholder="请选择合同" clearable>
            <el-option v-for="item in businessType" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="开票金额" prop="invoicedAmount">
          <el-input v-model="params.invoicedAmount" placeholder="请输入开票金额" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item> </el-form-item>
        <el-form-item label="合同金额(元)"> - </el-form-item>
        <el-form-item label="回款金额(元)"> - </el-form-item>
        <el-form-item label="未回款金额(元)"> - </el-form-item>
        <el-form-item label="已开票金额(元)"> - </el-form-item>
        <el-form-item label="可开票金额(元)"> - </el-form-item>
        <el-form-item label="开票税点扣除"> - </el-form-item>
      </div>
      <div class="p-title w-100 mb-12">发票详情</div>
      <div class="form-inline-wrap">
        <el-form-item label="选择发票抬头">
          <div class="w-100 flx-justify-between">
            <el-select class="flx-1" v-model="params.invoiceTitle" placeholder="请选择发票抬头" clearable>
              <el-option v-for="item in businessType" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <el-button class="ml-8" type="primary" plain @click="showAddForm = true">新建</el-button>
          </div>
        </el-form-item>
      </div>
      <div class="form-inline-wrap" v-if="showAddForm">
        <el-form-item label="发票类型" prop="invoiceType">
          <el-radio-group v-model="params.invoiceType">
            <el-radio value="1">普通发票</el-radio>
            <el-radio value="2">专用发票</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="抬头类型" prop="headUpType">
          <el-radio-group v-model="params.headUpType">
            <el-radio value="1">企业单位</el-radio>
            <el-radio value="2">个人/非企业单位</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="params.companyName" placeholder="请输入公司名称" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item label="公司税号" prop="companyTaxNumber">
          <el-input v-model="params.companyTaxNumber" placeholder="请输入公司税号" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item label="注册电话">
          <el-input v-model="params.registeredPhone" placeholder="请输入注册电话" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item label="注册地址">
          <el-input v-model="params.registeredAddress" placeholder="请输入注册地址" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item label="银行账户">
          <el-input v-model="params.bankAccount" placeholder="请输入银行账户" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item label="开户银行">
          <el-input v-model="params.depositaryBank" placeholder="请输入开户银行" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item label="保存为新的抬头">
          <el-switch
            v-model="params.save"
            inline-prompt
            active-text="是"
            inactive-text="否"
            :active-value="1"
            :inactive-value="0"
          />
        </el-form-item>
      </div>
    </el-form>
    <template #footer>
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
import { ref, reactive, defineEmits } from "vue";

const rules = reactive({
  collectionAccount: [{ required: true, message: "请选择收款账户" }],
  invoicedAmount: [{ required: true, message: "请输入开票金额" }],
  companyName: [{ required: true, message: "请输入公司名称" }],
  companyTaxNumber: [{ required: true, message: "请输入公司税号" }]
});

interface DrawerProps {
  title: string;
  id: number;
  getTableList?: () => void;
}

const drawerVisible = ref(false);
const drawerProps = ref<DrawerProps>({
  title: "",
  id: 0
});
const params = ref({});

// 业务类型
const businessType = ref([
  { label: "111", value: 1 },
  { label: "222", value: 2 }
]);

// 接收父组件传过来的参数
const acceptParams = (params: DrawerProps) => {
  drawerProps.value = params;
  drawerVisible.value = true;
};

// 是否显示新建表单
const showAddForm = ref(false);

// 提交数据（新增/编辑）
const ruleFormRef = ref();
const handleSubmit = () => {
  ruleFormRef.value!.validate(async valid => {
    if (!valid) return;
    try {
      //   await drawerProps.value.api!(drawerProps.value.row);
      //   ElMessage.success({ message: `${drawerProps.value.title}用户成功！` });
      //   drawerProps.value.search!();
      //   drawerVisible.value = false;
    } catch (error) {
      console.log(error);
    }
  });
};

const emit = defineEmits(["close"]);
const close = () => {
  drawerVisible.value = false;
  emit("close");
};

defineExpose({
  acceptParams
});
</script>
